/*
 * @name: 用户管理
 * @Author: along
 */
<template>
    <div class="container taskUserList">
        <!-- header -->
        <div class="header">
            <div class="header-list">
                <p class="header-title">学校名称</p>
                <el-cascader
                    placeholder="请选择"
                    :options="school_tree"
                    filterable
                    clearable
                    change-on-select
                    expand-trigger="click"
                    v-model="list.college_name"
                    @change="getTableData(1)"
                    :props="{
                        label: 'name',
                        value: 'id',
                        children: 'children'
                    }"
                    size="small"
                    style="height:32px;padding-left:8px"
                />
            </div>
            <div class="header-list">
                <p class="header-title">用户昵称</p>
                <el-input
                    v-model="list.true_name"
                    placeholder="请输入用户昵称"
                    suffix-icon="el-icon-search"
                    size="small"
                    class="cont-ipt"
                    clearable
                    @change="getTableData(1)"
                    @keyup.native.enter="getTableData(1)"
                />
            </div>
            <div class="header-list">
                <p class="header-title">邀请码</p>
                <el-input
                    v-model="list.invite_code"
                    placeholder="请输入邀请码"
                    suffix-icon="el-icon-search"
                    size="small"
                    class="cont-ipt"
                    clearable
                    @change="getTableData(1)"
                    @keyup.native.enter="getTableData(1)"
                />
            </div>
            <div class="header-list">
                <p class="header-title">上级关键词</p>
                <el-input
                    v-model="list.parent_keyword"
                    placeholder="上级邀请码或手机号或姓名"
                    suffix-icon="el-icon-search"
                    size="small"
                    class="cont-ipt"
                    clearable
                    @change="getTableData(1)"
                    @keyup.native.enter="getTableData(1)"
                />
            </div>
            <div class="header-list">
                <p class="header-title">手机号或ID</p>
                <el-input
                    v-model="list.phone"
                    placeholder="用户手机号或ID"
                    suffix-icon="el-icon-search"
                    size="small"
                    class="cont-ipt"
                    clearable
                    @change="getTableData(1)"
                    @keyup.native.enter="getTableData(1)"
                />
            </div>
            <div class="header-list">
                <p class="header-title">学院名称</p>
                <el-input
                    v-model="list.school_name"
                    placeholder="请输入学院名称"
                    suffix-icon="el-icon-search"
                    size="small"
                    class="cont-ipt"
                    clearable
                    @change="getTableData(1)"
                    @keyup.native.enter="getTableData(1)"
                />
            </div>
            <!-- <el-input
                v-model="list.college_name"
                placeholder="请输入学院名称"
                suffix-icon="el-icon-search"
                size="small"
                class="cont-ipt"
                clearable
                @change="getTableData(1)"
                @keyup.native.enter="getTableData(1)"
            /> -->
            <div class="header-list">
                <p class="header-title">IP城市搜索</p>
                <el-input
                    v-model="list.city_name"
                    placeholder="请输入城市名称"
                    suffix-icon="el-icon-search"
                    size="small"
                    class="cont-ipt"
                    clearable
                    @change="getTableData(1)"
                    @keyup.native.enter="getTableData(1)"
                />
            </div>
            <div class="header-list">
                <p class="header-title">注册时间</p>
                <el-date-picker
                    v-model="list.reg_time_range"
                    type="daterange"
                    class="cont-time"
                    size="small"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    value-format="yyyy-MM-dd"
                    @change="getTableData(1)"
                />
            </div>
            <div class="header-list">
                <p class="header-title">入学年份</p>
                <el-select
                    v-model="list.start_year"
                    clearable
                    placeholder="请选择"
                    class="cont-ipt"
                    size="small"
                    filterable
                    @change="getTableData(1)"
                >
                    <el-option
                        v-for="item in startYear"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"/>
                </el-select>
            </div>
            <div class="header-list">
                <p class="header-title">应用版本</p>
                <el-select
                    v-model="list.app_version"
                    clearable
                    placeholder="请选择"
                    class="cont-ipt"
                    size="small"
                    filterable
                    @change="getTableData(1)"
                >
                    <el-option
                        v-for="item in appVersion"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"/>
                </el-select>
            </div>
            <div class="header-list">
                <p class="header-title">操作系统</p>
                <el-select
                    v-model="list.os_name"
                    clearable
                    placeholder="请选择"
                    class="cont-ipt"
                    size="small"
                    filterable
                    @change="getTableData(1)"
                >
                    <el-option
                        v-for="item in osName"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"/>
                </el-select>
            </div>
            <div class="header-list">
                <el-button
                    @click="fnReset"
                    size="small"
                >重置</el-button>
                <el-button
                    @click="getTableData(1)"
                    size="small"
                    type="primary"
                >搜索</el-button>
                <el-button
                    @click="fnExport"
                    size="small"
                >数据导出</el-button>
                <el-button
                    size="small"
                    type="primary"
                    @click="dialogRecharge = true"
                >批量充值</el-button>
            </div>
        </div>
        <!-- /header -->

        <!-- table -->
        <el-table
            :data="tableData"
            height="100%"
            style="width: 100%;"
            border
            @sort-change="handleSortChanged"
        >
            <el-table-column
                type="selection"
                width="50"
            />
            <el-table-column
                label="序号"
                align="center"
                type="index"
            />
            <el-table-column
                prop="student_no"
                label="用户编号"
                show-overflow-tooltip
                :width="130"
                :formatter="emptyFormatter"
            />
            <el-table-column
                prop="true_name"
                label="用户姓名"
                show-overflow-tooltip
                :formatter="emptyFormatter"
            />
            <el-table-column
                :formatter="emptyFormatter"
                prop="phone"
                align="center"
                label="手机号"
                :width="120"
            />
            <el-table-column
                prop="invite_code"
                label="邀请码"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="center"
            />
            <el-table-column
                :formatter="emptyFormatter"
                prop="parent_stuagent"
                align="center"
                label="上级精英"
                :width="120"
            >
                <template slot-scope="scope">
                    <div v-if="scope.row.parent_stuagent === null">
                        --
                    </div>
                    <div v-else>
                        <p class="zd-line">{{ scope.row.parent_stuagent.true_name }}</p>
                        <p class="zd-line">{{ scope.row.parent_stuagent.phone }}</p>
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                :formatter="emptyFormatter"
                prop="reg_time"
                align="center"
                label="注册时间"
                width="140px"
                sortable='custom'
            >
                <template slot-scope="scope">
                    {{ scope.row.reg_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm') }}
                </template>
            </el-table-column>
            <el-table-column
                :formatter="emptyFormatter"
                prop="last_login_time"
                align="center"
                label="上次登录时间"
                width="150px"
                sortable='custom'
            >
                <template slot-scope="scope">
                    {{ scope.row.last_login_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm') }}
                </template>
            </el-table-column>
            <el-table-column
                :formatter="emptyFormatter"
                prop="last_view_time"
                align="center"
                label="最近访问时间"
                width="150px"
                sortable='custom'
            >
                <template slot-scope="scope">
                    {{ scope.row.last_view_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm') }}
                </template>
            </el-table-column>
            <el-table-column
                :formatter="emptyFormatter"
                align="center"
                label="IP地址"
                :width="120"
            >
                <template slot-scope="scope">
                    <span>
                        {{ scope.row.province_name }} - {{ scope.row.city_name }}
                    </span>
                </template>
            </el-table-column>
            <el-table-column
                :formatter="emptyFormatter"
                prop="app_version"
                align="center"
                label="应用版本"
            />
            <el-table-column
                :formatter="emptyFormatter"
                prop="os_name"
                align="center"
                label="操作系统"
            />
            <el-table-column
                :formatter="emptyFormatter"
                prop="device_model"
                align="center"
                label="手机设备-机型"
                width="150px"
            />
            <el-table-column
                prop="has_tao_auth"
                align="center"
                label="淘宝授权"
            >
                <template slot-scope="scope">
                    <span v-if="scope.row.has_tao_auth == 1">是</span>
                    <span v-if="scope.row.has_tao_auth == 0">否</span>
                </template>
            </el-table-column>
            <el-table-column
                prop="sex"
                align="center"
                label="性别"
            >
                <template slot-scope="scope">
                    <div
                        class="zd-sex"
                        @click="fnChangeSex(scope.row)"
                    >
                        <span v-if="scope.row.sex == 1">男</span>
                        <span v-if="scope.row.sex == 2">女</span>
                        <span v-if="scope.row.sex !== 2 && scope.row.sex !== 1">--</span>
                        <i class="el-icon-edit"/>
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                :formatter="emptyFormatter"
                prop="birth_time"
                align="center"
                label="出生日期"
                show-overflow-tooltip
            >
                <template slot-scope="scope">
                    <span>
                        {{ scope.row.birth_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm') }}
                    </span>
                </template>
            </el-table-column>
            <el-table-column
                prop="school_name"
                label="学校名称"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                :width="160"
            >
                <template slot-scope="scope">
                    <div
                        class="school-wrap"
                        style="color: #409EFF"
                        @click="copyUrl(scope.row.school_name)"
                    >
                        {{ scope.row.school_name | nameFilter }}
                        <span class="school-spliter" />
                        <el-button
                            type="text"
                            class="btn-school"
                            @click="fnEditSchool(scope.row)"
                        >
                            <i class="el-icon-edit" />
                        </el-button>
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                :formatter="emptyFormatter"
                show-overflow-tooltip
                prop="college_name"
                label="学院名称"
                :width="150"
            >
                <template slot-scope="scope">
                    <div class="school-wrap">
                        {{ scope.row.college_name | nameFilter }}
                        <span
                            class="school-spliter"
                            v-if="scope.row.college_name"
                        />
                        <el-button
                            type="text"
                            class="btn-school"
                            @click="fnEditClass(scope.row)"
                        >
                            <i
                                class="el-icon-edit"
                                v-if="scope.row.college_name"
                            />
                            <span v-else>--</span>
                        </el-button>
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                :formatter="emptyFormatter"
                show-overflow-tooltip
                prop="class_name"
                label="班级"
            />
            <el-table-column
                :formatter="emptyFormatter"
                prop="education_name"
                align="center"
                label="学制/学历"
                width="100px"
            >
                <template slot-scope="scope">
                    <span v-if="scope.row.education_name !== ''">
                        {{ scope.row.education_year }}/{{ scope.row.education_name }}
                    </span>
                    <span v-if="scope.row.education_name == ''">--</span>
                </template>
            </el-table-column>
            <el-table-column
                :formatter="emptyFormatter"
                prop="grade_name"
                align="center"
                label="大几"
            >
                <template slot-scope="scope">
                    <span v-if="scope.row.education_name !== '' ">{{ scope.row.grade_name }}</span>
                    <span v-if="scope.row.education_name == '' ">--</span>
                </template>
            </el-table-column>
            <el-table-column
                :formatter="emptyFormatter"
                show-overflow-tooltip
                prop="major_name"
                align="center"
                label="专业名称"
            />
            <el-table-column
                label="操作"
                align="center"
                fixed="right"
            >
                <template slot-scope="scope">
                    <span
                        class="curse-add"
                        @click="fnLookNum(scope.row)"
                    >查看统计</span>
                    <el-button
                        type="text"
                        class="curse-add"
                        style="padding:0"
                        @click="fnRecharge(scope.row)"
                    >
                        充值
                    </el-button>
                    <el-button
                        type="text"
                        class="curse-add"
                        v-if="scope.row.has_tao_auth == 1"
                        style="margin-left:0;padding:0"
                        @click="fnUnbind(scope.row)"
                    >
                        解绑
                    </el-button>
                    <el-button
                        type="text"
                        class="curse-add"
                        v-if="scope.row.status == 1"
                        style="margin-left:0;padding:0"
                        @click="fnProhibition(scope.row)"
                        :disabled="!authResult.auth_status"
                    >
                        封禁
                    </el-button>
                    <el-button
                        type="text"
                        class="curse-add"
                        v-if="scope.row.status == 0"
                        style="margin-left:0;padding:0"
                        @click="fnProhibition(scope.row)"
                        :disabled="!authResult.auth_status"
                    >
                        解封
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <!-- /table -->

        <!-- 分页 -->
        <div
            class="pagination-wrapper clearfix"
            v-if="tableData.length > 0"
        >
            <el-pagination
                background
                layout="total, prev, pager, next"
                :current-page.sync="page.now_page"
                :total="page.total_count"
                :page-size="page.page_size"
                @current-change="getTableData"
            />
        </div>
        <!-- /分页 -->

        <!-- 修改学校弹窗 -->
        <el-dialog
            style="text-align:center;"
            title="编辑学校名称"
            :visible.sync="dialogVisible"
            width="500px"
        >
            <span>学校名称:</span>
            <el-cascader
                v-model="school_name_edit"
                placeholder="请选择"
                :options="school_tree"
                filterable
                clearable
                change-on-select
                expand-trigger="click"
                :props="{
                    label: 'name',
                    value: 'id',
                    children: 'children'
                }"
                size="small"
            />
            <span
                slot="footer"
                class="dialog-footer">
                <el-button
                    type="primary"
                    size="small"
                    @click='submitEditForm()'>提交</el-button>
            </span>
        </el-dialog>
        <!-- /修改学校弹窗 -->

        <!-- 修改班级弹窗 -->
        <el-dialog
            style="text-align:center;"
            title="编辑学校名称"
            :visible.sync="dialogVisibleClass"
            width="500px"
        >
            <span>班级名称:</span>
            <el-cascader
                v-model="class_name_edit"
                :options="classNameList"
                size="small"
                :props="{
                    value: 'value',
                    label: 'label',
                    children: 'children'
                }"
                @change="handleChange"
            />
            <span
                slot="footer"
                class="dialog-footer">
                <el-button
                    type="primary"
                    size="small"
                    @click='submitEditFormClass()'>提交</el-button>
            </span>
        </el-dialog>
        <!-- /修改班级弹窗 -->

        <!-- 充值弹窗 -->
        <el-dialog
            title="充值"
            :visible.sync="dialogVisibleCharge"
            width="300px"
        >
            <div class="title">
                <span>标题:</span>
                <el-input
                    v-model="reChargeTitle"
                    @input="can"
                    placeholder="请输入标题"/>
            </div>
            <div class="money">
                <span>金额:</span>
                <el-input
                    v-model="reChargeNum"
                    @input="charge"
                    placeholder="请输入金额"/>
            </div>
            <span class="warning">确定后钱将打入对方账户，请谨慎操作！</span>

            <span
                slot="footer"
                class="dialog-footer"
            >
                <el-button
                    plain
                    size="small"
                    @click="dialogVisibleCharge = false">取消</el-button>
                <el-button
                    type="primary"
                    size="small"
                    :disabled="!chargeDisabled"
                    @click="fnGoCharge()">充值</el-button>
            </span>
        </el-dialog>
        <!-- 充值弹窗 -->

        <!-- 批量导出弹窗 -->
        <el-dialog
            title="批量充值"
            :visible.sync="dialogRecharge"
            width="520px"
        >
            <div class="recharge">
                <p class="recharge-text">
                    批量充值，最多给单个用户充值100元，如有用户超出，请手动充值
                </p>
                <div class="recharge-list">
                    导入表格并充值
                    <input
                        class="import-input"
                        accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"
                        type="file"
                        @change="fnExportFilt($event)">
                    <el-button
                        size="small"
                        type="text"
                        style="width:100px;margin-left:7px;text-decoration: underline;"
                    >
                        点击上传
                    </el-button>
                </div>
                <div class="recharge-list">
                    下载表格模版
                    <el-button
                        size="small"
                        type="text"
                        style="width:100px;margin-left:20px;text-decoration: underline;"
                        @click="fnImportFile()"
                    >
                        点击下载
                    </el-button>
                </div>
                <div class="recharge-foot">
                    <el-button
                        size="small"
                        type="default"
                        style="width:100px;"
                        @click="dialogRecharge = false"
                    >
                        取消
                    </el-button>
                </div>
            </div>
        </el-dialog>
    </div>
</template>

<script>
const sortFieldMap = {
    reg_time: 'reg_time',
    last_login_time: 'login_time',
    last_view_time: 'view_time'
};
const sortTypeMap = {
    'ascending': 'asc',
    'descending': 'desc'
};

export default {
    data () {
        return {
            dialogRecharge: false,//批量充值弹窗开关
            school_tree: [],
            class_no: '',
            classNameList: [],
            class_name_edit: '',
            dialogVisibleClass: false,
            list: {
                school_name: '',
                true_name: '',
                phone: '',
                college_name: '',
                city_name: '',
                reg_time_range: '',
                start_year: '',
                app_version: '',
                os_name: '',
                device_model: '',
                invite_code: '',
                parent_keyword: ''
            },
            school_name_edit:'',
            chargeDisabled: false,
            chargeStudent_no:'',
            dialogVisibleCharge: false,
            reChargeTitle:'',
            reChargeNum:'',
            tableData: [],
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 0
            },
            sortData: {
                field: '',
                by: ''
            },
            startYear: [{
                value: '',
                label: '全部'
            }],
            appVersion: [{
                value: '',
                label: '全部'
            }],
            osName: [{
                value: '',
                label: '全部'
            }],
            dialogVisible: false,
            forumList: [],
            optionSchool: [],
            schoolList:[],
            authResult: {}
        };
    },
    watch: {
        dialogVisible (val) {
            if(!val) {
                this.getSchoolList();
            }
        }
    },
    filters: {
        nameFilter (val) {
            if(val == '' || val == null || val ==undefined) {
                return '';
            }
            if (val.length > 7) {
                return val.slice(0,7) + '...';
            } else {
                return val;
            }
        }
    },
    created () {
        this.authResult = this.$route.meta.authResult;
        console.log(this.authResult);
        this.$store.commit('SET_HEADER', [{title: "APP后台",},{title: "用户管理"}]);

        if(this.$route.query) {
            this.list.phone = this.$route.query.student_no;
        }

        this.getTableData();
        this.getOptionList();
        this.getFullyear(2005);
        this.getSchoolList();
        this.getSchoolTree();
    },
    methods: {
        /**
         * 批量充值/上传文件
         */
        fnExportFilt (event) {
            let file = event.target.files[0];
            let form = new FormData();

            form.append("file", file);
            this.$post('/student/student_user%5Crecharge_import', form, resp => {
                event.target.value = null;
                if (resp.code == 1) {
                    this.dialogRecharge = !this.dialogRecharge;
                    this.$message({
                        type: 'success',
                        message: '充值成功',
                        center: true
                    });
                } else {
                    this.$alert(resp.msg, '提示', {
                        confirmButtonText: '确定',
                        callback: action => {
                            //
                        }
                    });
                }
            });
        },

        /**
         * 批量充值/下载文件
         */
        fnImportFile () {
            let base = this.$baseUrl;
            let ticket = localStorage.getItem('sessionTicket');
            let url = `${base}/student/student_user%5Crecharge_csv?__ticket=${ticket}`;

            window.open(url);
        },

        /**
         * 性别修改
         */
        fnChangeSex (row) {
            if(!this.authResult.auth_sex) {
                this.$message({
                    type: 'warning',
                    message: '此权限,仅限超级管理员',
                    center: true
                });
                return;
            }

            if(row.sex == 1) {
                this.$confirm('该用户当前性别为男，是否要修改为女？', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.$post('/student/student_user%5Cset_sex',{
                        student_no: row.student_no,
                        sex: 2
                    }, resp => {
                        if(resp.code == 1) {
                            this.getTableData();
                            this.$message({
                                type: 'success',
                                message: '修改成功!'
                            });
                        } else {
                            this.$message({
                                type: 'warning',
                                message: resp.msg,
                                center: true
                            });
                        }
                    });
                });
            }

            if(row.sex == 2) {
                this.$confirm('该用户当前性别为女，是否要修改为男？', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.$post('/student/student_user%5Cset_sex',{
                        student_no: row.student_no,
                        sex: 1
                    }, resp => {
                        if(resp.code == 1) {
                            this.getTableData();
                            this.$message({
                                type: 'success',
                                message: '修改成功!'
                            });
                        } else {
                            this.$message({
                                type: 'warning',
                                message: resp.msg,
                                center: true
                            });
                        }
                    });
                });
            }
        },

        /**
         * 获取省/市/学校三级联动
         */
        getSchoolTree () {
            this.$post('/student/local_info%5Cschool_tree',{},resp => {
                if (resp.code == 1) {
                    this.school_tree = resp.data.tree;
                } else {
                    this.$message({
                        type: 'warning',
                        message: '此权限,仅限超级管理员'
                    });
                }
            });
        },

        /**
         * 获取入学年份
         */
        getFullyear (startYear) {
            let year = new Date().getFullYear();
            let newYear = [];

            for(let i=year; i>=startYear; i--) {
                newYear.push({
                    value: i,
                    label: i
                });
            }
            this.startYear = this.startYear.concat(newYear);
        },

        /**
         * 获取选项列表数据
         */
        getOptionList () {
            this.$post('/student/student_user%5Coption_list', {
            },resp => {
                if (resp.code == 1) {
                    let osName = [];
                    let appVersion = [];

                    resp.data.os_list.map(item => {
                        osName.push({
                            value: item.os_name,
                            label: item.os_title
                        });
                    });
                    this.osName = this.osName.concat(osName);

                    resp.data.version_list.map(item => {
                        appVersion.push({
                            value: item.version_name,
                            label: item.version_title
                        });
                    });
                    this.appVersion = this.appVersion.concat(appVersion);
                }
            });
        },

        /**
         * 获取表格数据
         */
        getTableData (page) {
            let reg = /-/img;
            let time = '';

            if (this.list.reg_time_range.length > 0) {
                time = this.list.reg_time_range[0].replace(reg, '') + '-' + this.list.reg_time_range[1].replace(reg, '');
            }

            this.$post('/student/student_user%5Cget_list', {
                page_id: page || this.page.now_page,
                // school_name: this.list.school_name,
                true_name: this.list.true_name,
                keyword_student_id: this.list.phone,
                college_name: this.list.school_name,
                city_name: this.list.city_name,
                start_year: this.list.start_year,
                app_version: this.list.app_version,
                os_name: this.list.os_name,
                device_model: this.list.device_model,
                reg_time_range: time,
                sort_field: this.sortData.field,
                sort_type: this.sortData.by,
                province_id: this.list.college_name.length >= 1 ? this.list.college_name[0] : '',
                city_id: this.list.college_name.length >= 2 ? this.list.college_name[1] : '',
                school_id: this.list.college_name.length >= 3 ? this.list.college_name[2] : '',
                invite_code: this.list.invite_code,
                parent_keyword: this.list.parent_keyword
            }, resp => {
                if (resp.code == 1) {
                    this.tableData = resp.data.list;
                    this.page.now_page = resp.data.page.now_page;
                    this.page.total_count = resp.data.page.total_count;
                    this.page.page_size = resp.data.page.page_size;
                }
            });
        },

        /**
         * 重置
         */
        fnReset () {
            let list = JSON.stringify(this.list);
            let newList = JSON.parse(list);

            for(let i in newList){
                newList[i] = '';
            }

            this.list = {
                ...newList
            };
            this.getTableData(1);
        },

        /**
         * 数据导出
         */
        fnExport () {
            let reg = /-/img;
            let time = '';
            let base = this.$baseUrl;
            let ticket = localStorage.getItem('sessionTicket');
            let {school_name, true_name, phone, college_name, city_name, reg_time_range, start_year, app_version, os_name, device_model} = this.list;

            if (this.list.reg_time_range.length > 0) {
                time = this.list.reg_time_range[0].replace(reg, '') + '-' + this.list.reg_time_range[1].replace(reg, '');
            }

            console.log({
                school_name: school_name,
                college_name: college_name,
                true_name: true_name,
                phone: phone,
                start_year: start_year,
                city_name: city_name,
                app_version: app_version,
                os_name: os_name,
                reg_time_range: reg_time_range,
            });

            let url = `${base}/student/student_user%5Cexport?school_name=${school_name}&college_name=${college_name}&true_name=${true_name}&phone=${phone}&start_year=${start_year}&city_name=${city_name}&app_version=${app_version}&os_name=${os_name}&reg_time_range=${time}&__ticket=${ticket}`;

            window.open(url);
        },

        /**
         * 查看统计
         */
        fnLookNum (row) {
            this.$message({
                type: 'warning',
                message: '当前版本暂不支持此功能'
            });
        },

        /**
         * 排序
         */
        handleSortChanged (data) {
            if (data.order) {
                this.sortData.field = sortFieldMap[data.prop];
                this.sortData.by = sortTypeMap[data.order];
            }

            this.getTableData();
        },

        /**
         * 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) {
                return '--';
            }
            return val;
        },
        /**
         * 编辑学校
         */
        fnEditSchool(row){
            if(this.authResult.auth_school_edit) {
                this.$confirm('慎重考虑是否修改?', '提示', {
                    confirmButtonText: '修改',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.dialogVisible = true;
                    this.changeStudent = row.student_no;
                    this.school_name_edit = row.school_id;
                }).catch((error) => {
                    console.log('error' + error);
                });
            } else {
                this.$message({
                    type: 'warning',
                    message: '此权限,仅限超级管理员'
                });
            }
        },

        /**
         * 获取学院班级二级联动
         */
        getClassName (id) {
            this.$post('/student/region_class%5Cget_college_cascade_list', {
                school_id: id
            },resp => {
                if(resp.code == 1) {
                    let list = [];

                    resp.data.college_list.map((item,index)=> {
                        list.push({
                            value: item.college_no,
                            label: item.college_name,
                            children: []
                        });
                        item.class_list.map((option,key) => {
                            list[index].children.push({
                                value: option.class_no,
                                label: option.class_name
                            });
                        });
                    });

                    this.classNameList = list;
                }
            });
        },

        /**
         * 选择班级
         */
        handleChange () {
            console.log(this.class_name_edit, 'class_name_edit');
        },

        /**
         * 提交班级
         */
        submitEditFormClass () {
            this.$post('/student/student_user%5Cchange_class', {
                student_no: this.changeStudent,
                class_no: this.class_name_edit.length > 0 ? this.class_name_edit[1] : ''
            },resp => {
                if(resp.code == 1) {
                    this.dialogVisibleClass = !this.dialogVisibleClass;
                    this.getTableData(this.page.now_page);
                    this.$message({
                        type: 'success',
                        message: '修改成功!'
                    });
                } else {
                    this.$message({
                        type: 'warning',
                        message: resp.msg
                    });
                }
            });
        },

        /**
         * 编辑班级
         */
        fnEditClass(row) {
            if(row.class_name == '') {
                this.$message({
                    type: 'warning',
                    message: '班级为空时不可编辑'
                });
                return;
            }

            if(this.authResult.auth_class_edit) {
                this.getClassName(row.school_id);
                this.dialogVisibleClass = !this.dialogVisibleClass;
                this.changeStudent = row.student_no;
                this.class_name_edit = [
                    row.college_no,
                    row.class_no
                ];
            } else {
                this.$message({
                    type: 'warning',
                    message: '此权限,仅限超级管理员'
                });
            }
        },
        /**
         * 获取已开通学校列表
         */
        getSchoolList () {
            this.$post('/student/forum%5Cget_school_list', {}, resp => {
                if (resp.code == 1) {
                    let list = [];
                    let foum = [];

                    resp.data.list.map(item => {
                        list.push({
                            value: item.school_id,
                            label: item.school_name
                        });
                        foum.push({
                            value: item.forum_no,
                            label: item.school_name
                        });
                    });

                    this.forumList = this.forumList.concat(foum);
                    this.optionSchool = this.optionSchool.concat(list);
                    this.schoolList = this.schoolList.concat(list);
                }
            });
        },
        handleClose(){
            this.dialogVisible = false;
        },
        submitEditForm(formName) {
            this.dialogVisible = false;
            this.$post('/student/student_user%5Cchange_school', {
                student_no: this.changeStudent,
                school_id: this.school_name_edit.length > 0 ? this.school_name_edit[2] : ''
            }, resp => {
                if (resp.code == 1) {
                    this.getTableData(1);
                    this.$message({
                        type: 'success',
                        message: '操作成功!'
                    });
                } else if (resp.code == 0) {
                    this.$message({
                        type: 'warning',
                        message: resp.msg
                    });
                }
            });
        },
        fnRecharge(row){
            this.dialogVisibleCharge = true;
            this.chargeStudent_no = row.student_no;
        },
        fnUnbind(row) {
            this.$confirm('是否要解绑淘宝账号?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$post('/student/student_user%5Cremove_tao_auth', {
                    student_no: row.student_no,
                }, resp => {
                    if (resp.code == 1) {
                        this.getTableData(1);
                        this.$message({
                            type: 'success',
                            message: '解绑成功!'
                        });
                    } else if (resp.code == 0) {
                        this.$message({
                            type: 'warning',
                            message: resp.msg
                        });
                    }
                });
            }).catch((error) => {
                console.log('error' + error);
            });
        },
        fnProhibition(row){
            if(row.status) {
                this.$confirm('是否封禁?', '提示', {
                    confirmButtonText: '确认',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.$post('/student/student_user%5Cset_status', {
                        student_no: row.student_no,
                        status: 0
                    }, resp => {
                        if(resp.code == 1){
                            this.$set(row, 'status', 0);
                            this.$notify({
                                type: '成功',
                                title: '封禁成功',
                                message: resp.msg,
                            });
                        } else if(resp.code == 0){
                            this.$notify({
                                title: '警告',
                                type: 'warning',
                                message: resp.msg,
                            });
                        }

                    });
                });
            } else {
                this.$post('/student/student_user%5Cset_status', {
                    student_no: row.student_no,
                    status: 1
                }, resp => {
                    if(resp.code == 1){
                        this.$set(row, 'status', 1);
                        this.$notify({
                            type: 'success',
                            title: '解封成功',
                            message: resp.msg,
                        });
                    } else if(resp.code == 0){
                        this.$notify({
                            title: '警告',
                            type: 'warning',
                            message: resp.msg,
                        });
                    }

                });
            }
        },
        fnGoCharge(){
            this.dialogVisibleCharge = false;
            this.$post('/student/student_user%5Cchange_money', {
                student_no: this.chargeStudent_no,
                title:this.reChargeTitle,
                money:this.reChargeNum,
            }, resp => {
                if(resp.code == 1){
                    this.$notify({
                        title: '成功',
                        message: resp.msg,
                    });
                } else if(resp.code == 0){
                    this.$notify({
                        type: 'warning',
                        title: '警告',
                        message: resp.msg,
                    });
                }

            });
        },
        can(){
            if(this.reChargeTitle!=''&& this.reChargeNum!=''){
                this.chargeDisabled = true;
            } else {
                this.chargeDisabled = false;
            }
        },
        charge(){
            if(this.reChargeTitle!=''&& this.reChargeNum!=''){
                this.chargeDisabled = true;
            } else {
                this.chargeDisabled = false;
            }
        },
        /**
         * @description 复制
         */
        copyUrl (url) {
            let str = url;
            let oInput = document.createElement("input");

            oInput.value = str;
            document.body.appendChild(oInput);
            oInput.select();
            document.execCommand("Copy");
            oInput.style.display = "none";
            this.$notify({
                title: '提示',
                message: '复制成功',
                type: 'success',
                duration: 2000
            });
        },
    }
};
</script>

<style lang="less" scoped>
    .container {
        width: 100%;
        background-color: #fff;
        padding: 15px;
        display: flex;
        flex-direction: column;
        position: relative;
        .header {
            margin-bottom: 0px;
            position: relative;
            display: flex;
            align-items: center;
            flex-wrap: wrap;
            .header-top {
                display: flex;
                flex-wrap: wrap;
                align-items: center;
                width: 100%;
            }
            .header-bottom {
                display: flex;
                align-items: center;
                width: 100%;
                margin-top: 10px;
            }
            .header-list {
                margin-right: 25px;
                display: flex;
                align-items: center;
                margin-bottom: 10px;
                .header-title {
                    white-space: nowrap;
                    color: #606266;
                }
                .cont-ipt {
                    width: 150px;
                    margin-left: 10px;
                }
                .cont-time {
                    margin-left: 10px;
                }
            }
            .header-right {
                display: flex;
                .el-button {
                    margin-left: 20px;
                }
            }
        }
        .curse-add {
            color: rgb(64, 158, 255);
            cursor: pointer;
        }
        .pagination-wrapper {
            padding-top: 10px;
            .el-pagination {
                float: right;
                padding: 0;
                background-color: transparent;
            }
        }
        .dialog-footer {
            display: flex;
            justify-content: center;
            align-items: center;
        }
    }
    .school-wrap {
        display: flex;
        align-items: center;
        cursor: pointer;
        .school-spliter {
            width: 1px;
            height: 12px;
            background: rgba(235, 235, 235, 1);
            margin: 0 10px;
        }
        .btn-school {
            font-size: 14px;
            line-height: 1;
            color: #ccc;
            &:hover {
                color: #20a0ff;
            }
        }
    }
    .title , .money{
        .el-input{
            width: 200px;
            display: inline-block;
            margin-left: 5px;
        }
        span{
            position: relative;
        }
        span:before{
            content: '*';
            display: block;
            color: red;
            position: absolute;
            top: 5px;
            left: -9px;
        }
    }
    .money{
        margin-top: 15px;
    }
    .warning{
        display: block;
        margin-top: 5px;
        margin-left: 40px;
        font-size: 12px;
        color: red;
    }
    .zd-line {
        white-space: nowrap;
    }
    .recharge {
        display: flex;
        flex-direction: column;
        .recharge-text {
            color: #F8A127;
            font-size: 13px;
        }
        .recharge-list {
            height: 32px;
            display: flex;
            align-items: center;
            color: #333333;
            font-size: 14px;
            margin-top: 20px;
            position: relative;
            .import-input {
                position: absolute;
                left: 0;
                top: 0;
                opacity: 0;
            }
        }
        .recharge-foot {
            height: 32px;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-top: 30px;
        }
    }
    .zd-sex {
        cursor: pointer;
    }
    .zd-sex:hover {
        color: #20a0ff;
    }
</style>
<style lang="less">
.taskUserList {
    .el-table__body-wrapper .el-table__body .el-table__row td {
        border-right: none;
    }
    .el-table__header-wrapper .el-table__header .has-gutter tr th {
        border-right: none;
    }
    .el-range-editor .el-range-input {
        line-height: 1;
        margin-left: 13px;
    }
    .el-dialog__body {
        padding: 10px 20px 30px 20px;
    }
}
</style>
